package com.heu.blood.config;

import com.heu.blood.common.Constant.UserConstantData;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Web MVC 配置类
 * 用于配置静态资源访问
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    private static final Logger log = LoggerFactory.getLogger(WebMvcConfig.class);

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 配置签名图片的静态资源访问
        String signPath = UserConstantData.getSignUrlPath();
        log.info("WebMvcConfig - 配置签名路径: " + signPath);

        // 确保路径以斜杠结尾
        if (!signPath.endsWith("/") && !signPath.endsWith("\\")) {
            signPath += "/";
        }

        String resourceLocation = "file:" + signPath;
        log.info("WebMvcConfig - 资源映射: /static/signpng/** -> " + resourceLocation);

        registry.addResourceHandler("/static/signpng/**")
                .addResourceLocations(resourceLocation);
    }
}